package com.zch.mobile;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.base.mobile.MobException;
import com.base.mobile.MobileInfo;
import com.base.mobile.server.annotation.Mobile;
import com.base.mobile.server.annotation.MobileMethod;
import com.base.util.DateUtil;
import com.bf.common.proto.MCommon.MRet;
import com.item.dao.model.User;
import com.item.service.UserService;
import com.zch.dao.model.CompanyRegister;
import com.zch.dao.model.CompanyRegisterExample;
import com.zch.dao.model.ManagerFollow;
import com.zch.dao.model.ProjectAnalyze;
import com.zch.dao.model.ProjectAnalyzeExample;
import com.zch.dao.model.ProjectConnect;
import com.zch.dao.model.ProjectConnectExample;
import com.zch.dao.model.ProjectMessage;
import com.zch.daoEx.model.CompanyRegisterEx;
import com.zch.daoEx.model.ProjectConnectEx;
import com.zch.service.CompanyRegisterService;
import com.zch.service.ManagerFollowService;
import com.zch.service.ProjectAnalyzeService;
import com.zch.service.ProjectConnectService;
import com.zch.service.ProjectMessageService;

import jxl.write.DateFormat;

@Mobile
@Component
public class MSendProject {
    @Autowired
    private ProjectMessageService projectMessageService;
    @Autowired
    private ProjectAnalyzeService projectAnalyzeService;
    @Autowired
    private ProjectConnectService projectConnectService;
    @Autowired
    private CompanyRegisterService companyRegisterService;
    @Autowired
    private ManagerFollowService managerFollowService;
    @Autowired
    private UserService userService;

    
    /**
     * 项目发布
     * @param mobileInfo
     * @param title
     * @param cy_type
     * @param investor
     * @param operation
     * @param manager
     * @param phone
     * @param total
     * @param zaiti_type
     * @param area
     * @param content
     * @param image
     * @param project_state
     * @param is_enable
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendProject", isLogin = true)
    public MRet.Builder SendProject(MobileInfo mobileInfo, 
                                    String title, 
                                    String cy_type,
                                    String investor,
                                    String operation, 
                                    String manager,
                                    String phone, 
                                    String total, 
                                    String zaiti_type, 
                                    String area,
                                    String content,
                                    String image) throws Exception{
        if (StringUtils.isBlank(title)) throw new MobException("title");
        if (StringUtils.isBlank(cy_type)) throw new MobException("cy_type");
        if (StringUtils.isBlank(investor)) throw new MobException("investor");
        if (StringUtils.isBlank(operation)) throw new MobException("operation");
        if (StringUtils.isBlank(manager)) throw new MobException("manager");
        if (StringUtils.isBlank(phone)) throw new MobException("phone");
        if (StringUtils.isBlank(total)) throw new MobException("total");
        if (StringUtils.isBlank(zaiti_type)) throw new MobException("zaiti_type");
        if (StringUtils.isBlank(area)) throw new MobException("area");
        if (StringUtils.isBlank(content)) throw new MobException("content");
        MRet.Builder ret= MRet.newBuilder();
        if(title.length()>=100){
            ret.setCode(-1);
            ret.setMsg("标题请控制在100个字以内...");
            return ret;
        }
        if(content.length()>=500){
            ret.setCode(-1);
            ret.setMsg("项目建设内容请控制在500个字以内...");
            return ret;
        }
        Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$");
        Matcher isNum = pattern.matcher(total);
        if(!isNum.matches()){
            ret.setCode(-1);
            ret.setMsg("请输入正确金额(小数点2位)...");
            return ret;
        }
        if(!area.matches("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$")){
            ret.setCode(-1);
            ret.setMsg("需求正确面积(小数点2位)...");
            return ret;   
        }
        ProjectMessage projectMessage = new ProjectMessage();
        projectMessage.setUserId(mobileInfo.getUserid());
        projectMessage.setTitle(title);
        projectMessage.setCyTypeId(cy_type);
        projectMessage.setInvestor(investor);
        projectMessage.setOperation(operation);
        projectMessage.setManager(manager);
        projectMessage.setPhone(phone);
        BigDecimal  str= new BigDecimal(total);
        projectMessage.setTotal(str);
        projectMessage.setZaitiType(zaiti_type);
        projectMessage.setArea(area);
        projectMessage.setContent(content);
        projectMessage.setImage(image);
        projectMessage.setProjectState(0);
        projectMessage.setIsEnable(0);
        projectMessage.setIsAgree(0);
        
        int result = projectMessageService.insert(projectMessage);
        if (result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ret.setCode(1);
        return ret;
    }
    
    
    /**
     * 项目--发布可行性分析
     * @param mobileInfo
     * @param content
     * @param image
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendProjectAnalyze", isLogin = true)
    public MRet.Builder SendProjectAnalyze(MobileInfo mobileInfo, String content, String image, String project_id)throws Exception{
        if (StringUtils.isBlank(content)) throw new MobException("content");
        if (StringUtils.isBlank(project_id)) throw new MobException("project_id");
        MRet.Builder ret= MRet.newBuilder();
        if(content.length()>=500){
            ret.setCode(-1);
            ret.setMsg("内容请控制在500个字以内...");
            return ret;
        }
        
        ProjectMessage projectMessage = projectMessageService.selectByPrimaryKey(project_id);
        //项目不存在
        if (projectMessage == null){
            throw new MobException("项目不存在");
        }
        //项目已经终止
        if (projectMessage.getIsEnable() == 1){
            throw new MobException("项目已经终止");
        }
        //不是可行性分析状态
        if (projectMessage.getProjectState() != 1){
            throw new MobException("当前还不可以进行可行性分析");
        }
        
        ProjectAnalyze projectAnalyze = new ProjectAnalyze();
        projectAnalyze.setUserId(mobileInfo.getUserid());
        projectAnalyze.setConnectMaster(mobileInfo.getUserid());
        projectAnalyze.setContent(content);
        projectAnalyze.setImage(image);
        projectAnalyze.setProjectId(project_id);
        projectAnalyze.setCreateTime(new Date());
        projectAnalyze.setIsAgree(0);
        
        ProjectAnalyzeExample example = new ProjectAnalyzeExample();
        example.createCriteria().andProjectIdEqualTo(project_id);
        
        int update = projectAnalyzeService.updateByExampleSelective(projectAnalyze, example);
        
        if (update == 0){
        	projectAnalyze.setIsEnable(0);
        	int result = projectAnalyzeService.insert(projectAnalyze);
            if (result == 0){
                throw new MobException(MZchError.SERVER_BUSY_ERROR);
            }
        }
        
        
        
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 项目--项目对接，跟踪汇报
     * @param mobileInfo
     * @param project_id 项目id
     * @param project_manager 项目负责人
     * @param connect_company   对接项目单位
     * @param job   职位
     * @param phone 电话
     * @param content   对接内容
     * @param image 图片
     * @param type  对接类型(1:对接 2:跟踪汇报)
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendProjectConnect", isLogin = true)
    public MRet.Builder SendProjectConnect(MobileInfo mobileInfo, 
                                           String project_id, 
                                           String project_manager,
                                           String connect_company,
                                           String job,
                                           String phone,
                                           String content,
                                           String image,
                                           String type) throws Exception{
        if (StringUtils.isBlank(project_id)) throw new MobException("project_id");
        
        if (StringUtils.isBlank(content)) throw new MobException("content");
        if (StringUtils.isBlank(type)) throw new MobException("type");
        MRet.Builder ret= MRet.newBuilder();
        if(content.length()>=500){
            ret.setCode(-1);
            ret.setMsg("内容请控制在500个字以内...");
            return ret;
        }
        
            ProjectConnect projectConnect = new ProjectConnect();
            projectConnect.setProjectId(project_id);
            projectConnect.setUserId(mobileInfo.getUserid());
            projectConnect.setProjectManager(project_manager);
            projectConnect.setConnectCompany(connect_company);
            projectConnect.setJob(job);
            projectConnect.setPhone(phone);
            projectConnect.setContent(content);
            projectConnect.setImage(image);
            projectConnect.setIsFinish(0);
            if(type.equals("1")){//对接
                if (StringUtils.isBlank(connect_company)) throw new MobException("connect_company");
                if (StringUtils.isBlank(job)) throw new MobException("job");
                if (StringUtils.isBlank(phone)) throw new MobException("phone");
                projectConnect.setType(1+"");
                projectConnect.setProjectConnectManager(mobileInfo.getUserid());
            }else if(type.equals("2")){//跟踪汇报
                projectConnect.setType(2+"");
                projectConnect.setProjectConnectManager(mobileInfo.getUserid());
            }
            projectConnect.setIsAgree(0);
            projectConnect.setIsEnable(0);
            
            int result = projectConnectService.insert(projectConnect);
            if (result == 0){
                throw new MobException(MZchError.SERVER_BUSY_ERROR);
            }
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", project_id);
            Boolean b = projectMessageService.updateMsg(map);
            if(b == false){
                throw new MobException(MZchError.SERVER_BUSY_ERROR);
            }
            
            ret.setCode(1);
            return ret;
        }
    /**
     * 对接终止
     * @param mobileInfo
     * @param project_id 项目ud
     * @param type type=1对接终止
     * @param reason 对接终止原因
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendProjectConnectShutDown", isLogin = true)
    public MRet.Builder SendProjectConnectShutDown(MobileInfo mobileInfo, String project_id, String type, String reason, String otherReason)throws Exception{     
        if (StringUtils.isBlank(project_id)) throw new MobException("project_id");
        if (StringUtils.isBlank(type)) throw new MobException("type");
        if (StringUtils.isBlank(reason)) throw new MobException("reason");
        MRet.Builder ret= MRet.newBuilder();
        String project_shutdown_reason = "";
      //对接终止
        if(type.equals("1")){
            if(reason.equals("1")){
                project_shutdown_reason="投资方改变投资意向";
            }else if(reason.equals("2")){
                project_shutdown_reason="无适合载体";
            }else if(reason.equals("3")){
                project_shutdown_reason="无优惠政策";
            }else if(reason.equals("4")){
                project_shutdown_reason="无产业配套";
            }else if(reason.equals("5")){
                project_shutdown_reason="无人才支持";
            }else if(reason.equals("6")){
                if (StringUtils.isBlank(otherReason)) throw new MobException("otherReason");
                if(otherReason.length()>=500){
                    ret.setCode(-1);
                    ret.setMsg("原因请控制在500个字以内...");
                    return ret;
                }
                project_shutdown_reason=otherReason;
            }
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", project_id);
        map.put("project_shutdown_reason", project_shutdown_reason);
        map.put("image", project_shutdown_reason);
        Boolean b = projectMessageService.updateProjectShutdownReason(map);
        if(b==false){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 项目对接完成
     * @param mobileInfo
     * @param zaitiType 载体类型
     * @param type type=1对接完成
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MSendProjectConnectResult", isLogin = true)
    public MRet.Builder SendProjectConnectResult(MobileInfo mobileInfo, 
                                                 String zaitiType, 
                                                 String type, 
                                                 String project_id,
                                                 String id)throws Exception{ 
        if (StringUtils.isBlank(zaitiType)) throw new MobException("zaitiType");
        if (StringUtils.isBlank(type)) throw new MobException("type");
        if (StringUtils.isBlank(project_id)) throw new MobException("project_id");
        Map<String, Object> map = new HashMap<String, Object>();
        
        ProjectConnect ex = projectConnectService.selectByPrimaryKey(id);
        ProjectConnect projectConnect = new ProjectConnect();
        projectConnect.setProjectConnectManager(ex.getProjectConnectManager());
        projectConnect.setProjectId(project_id);
        projectConnect.setProjectManager(ex.getProjectManager());
        projectConnect.setConnectCompany(ex.getConnectCompany());
        projectConnect.setJob(ex.getJob());
        projectConnect.setPhone(ex.getPhone());
        projectConnect.setContent(ex.getContent());
        projectConnect.setUserId(ex.getUserId());
        projectConnect.setProjectConnectManager(ex.getProjectConnectManager());
        projectConnect.setImage(ex.getImage());
        projectConnect.setIsAgree(ex.getIsAgree());
        projectConnect.setType(ex.getType());
        projectConnect.setIsEnable(ex.getIsEnable());
        projectConnect.setNotAgreeReason(ex.getNotAgreeReason());
        projectConnect.setIsFinish(1);
        projectConnect.setZaitiType(zaitiType);
        projectConnect.setCreateTime(new Date());
        int result = projectConnectService.insert(projectConnect);
        if(result!=1){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        map.put("id", project_id);
        Boolean b = projectMessageService.updateProjectConnectResult(map);
        if(b==false){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
//        if(type.equals("1")){
//            map.put("id", project_id);
//            map.put("zaitiType", zaitiType);           
//        }
//        Boolean result = projectConnectService.updateIsFinish(map);
//        if(result==false){
//            throw new MobException(MZchError.SERVER_BUSY_ERROR);
//        }
//        Boolean b = projectMessageService.updateProjectConnectResult(map);
//        if(b==false){
//            throw new MobException(MZchError.SERVER_BUSY_ERROR);
//        }
        
        
        MRet.Builder ret= MRet.newBuilder();
        ret.setCode(1);
        return ret;
        
    }
    
    
    /**
     * 项目公司注册
     * @param mobileInfo
     * @param register_name
     * @param company_name
     * @param address
     * @param register_money
     * @param register_date
     * @param master
     * @param phone
     * @param ranges
     * @param project_id
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MCompanyRegister", isLogin = true)
    public MRet.Builder CompanyRegister(MobileInfo mobileInfo, 
                                        String register_name,
                                        String company_name,
                                        String address,
                                        String register_money,
                                        String register_date,
                                        String master,
                                        String phone,
                                        String ranges,
                                        String project_id)throws Exception{
        if (StringUtils.isBlank(register_name)) throw new MobException("register_name");
        if (StringUtils.isBlank(company_name)) throw new MobException("company_name");
        if (StringUtils.isBlank(address)) throw new MobException("address");
        if (StringUtils.isBlank(register_money)) throw new MobException("register_money");
        if (StringUtils.isBlank(register_date)) throw new MobException("register_date");
        if (StringUtils.isBlank(master)) throw new MobException("master");
        if (StringUtils.isBlank(phone)) throw new MobException("phone");
        if (StringUtils.isBlank(ranges)) throw new MobException("ranges");
        if (StringUtils.isBlank(project_id)) throw new MobException("project_id");
        MRet.Builder ret= MRet.newBuilder();
        
        if(register_name.length()>=50){
            ret.setCode(-1);
            ret.setMsg("工商登记名称请控制在50个字以内...");
            return ret;
        }
        if(company_name.length()>=50){
            ret.setCode(-1);
            ret.setMsg("企业名称名称请控制在50个字以内...");
            return ret;
        }
        if(address.length()>=50){
            ret.setCode(-1);
            ret.setMsg("地址请控制在50个字以内...");
            return ret;
        }
        Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$");
        Matcher isNum = pattern.matcher(register_money);
        if(!isNum.matches()){
            ret.setCode(-1);
            ret.setMsg("请输入正确金额(小数点2位)...");
            return ret;
        }
        if(ranges.length()>=50){
            ret.setCode(-1);
            ret.setMsg("经营范围请控制在50个字以内...");
            return ret;
        }
        
        CompanyRegister companyRegister = new CompanyRegister();
        CompanyRegisterExample example = new CompanyRegisterExample();
        example.createCriteria().andProjectIdEqualTo(project_id);
        List<CompanyRegister> list = companyRegisterService.selectByExample(example);
        if (list.size() == 0){
            //bucunzai insert
            companyRegister.setRegisterManagerId(mobileInfo.getUserid());
            companyRegister.setUserId(mobileInfo.getUserid());
            companyRegister.setRegisterName(register_name);
            companyRegister.setCompanyName(company_name);
            companyRegister.setAddress(address);
            BigDecimal  str= new BigDecimal(register_money);
            companyRegister.setRegisterMoney(str);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse(register_date);
            companyRegister.setRegisterDate(date);
            companyRegister.setMaster(master);
            companyRegister.setPhone(phone);
            companyRegister.setRanges(ranges);
            companyRegister.setProjectId(project_id);
            companyRegister.setIsEnable(0);
            companyRegister.setIsAgree(0);
            companyRegister.setUserId(mobileInfo.getUserid());
            int result = companyRegisterService.insert(companyRegister);
            if(result == 0){
                throw new MobException(MZchError.SERVER_BUSY_ERROR);
            }
        }else{
            CompanyRegister companyRegister2 = list.get(0);
            if (companyRegister2.getIsAgree() != 0){
                throw new MobException("项目注册公司还未被审核...");
            }
            companyRegister.setId(companyRegister2.getId());
            companyRegister.setRegisterManagerId(mobileInfo.getUserid());
            companyRegister.setUserId(mobileInfo.getUserid());
            companyRegister.setRegisterName(register_name);
            companyRegister.setCompanyName(company_name);
            companyRegister.setAddress(address);
            BigDecimal  str= new BigDecimal(register_money);
            companyRegister.setRegisterMoney(str);
            if(register_date==null){
                throw new Exception("时间格式错误");
            }
            companyRegister.setRegisterDate(DateUtil.strToDate(register_date,"yyyy-MM-dd"));
            companyRegister.setMaster(master);
            companyRegister.setPhone(phone);
            companyRegister.setRanges(ranges);
            companyRegister.setProjectId(project_id);
            companyRegister.setIsEnable(0);
            companyRegister.setIsAgree(0);
            companyRegister.setUserId(mobileInfo.getUserid());
            int result = companyRegisterService.updateByPrimaryKeySelective(companyRegister);
            if(result == 0){
                throw new Exception("项目注册公司还在审核中请耐心等待...");
            }else if(result == 1){
                //throw new Exception("更新成功！");
            }
        }
            
        
        
        
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 项目运营跟踪
     * @param mobileInfo
     * @param employ_num
     * @param income
     * @param beginDate
     * @param endDate
     * @param content
     * @param resolve_content
     * @param type
     * @param project_id
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MProjectFollow", isLogin = true)
    public MRet.Builder ProjectFollow(MobileInfo mobileInfo, 
                                        String employ_num,
                                        String income,
                                        String beginDate,
                                        String endDate,
                                        String content,
                                        String resolve_content,
                                        String type,
                                        String project_id)throws Exception{
        if (StringUtils.isBlank(employ_num)) throw new MobException("employ_num");
        if (StringUtils.isBlank(income)) throw new MobException("income");
        if (StringUtils.isBlank(beginDate)) throw new MobException("beginDate");
        if (StringUtils.isBlank(endDate)) throw new MobException("endDate");
        if (StringUtils.isBlank(content)) throw new MobException("content");
        if (StringUtils.isBlank(resolve_content)) throw new MobException("resolve_content");
        if (StringUtils.isBlank(type)) throw new MobException("type");
        if (StringUtils.isBlank(project_id)) throw new MobException("project_id");
        User  user = userService.selectByPrimaryKey(mobileInfo.getUserid());
        MRet.Builder ret= MRet.newBuilder();
        Pattern pattern = Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$");
        Matcher isNum = pattern.matcher(income);
        if(!isNum.matches()){
            ret.setCode(-1);
            ret.setMsg("请输入正确金额(小数点2位)...");
            return ret;
        }
        if(content.length()>=500){
            ret.setCode(-1);
            ret.setMsg("公司运营情况请输入500个字以内...");
            return ret;
        }
        if(resolve_content.length()>=500){
            ret.setCode(-1);
            ret.setMsg("企业需解决协调的问题请输入500个字以内...");
            return ret;
        }
        
        ManagerFollow managerFollow = new ManagerFollow();
        managerFollow.setFollowMaster(mobileInfo.getUserid());
        managerFollow.setUserId(mobileInfo.getUserid());
        managerFollow.setEmployNum(employ_num);
        managerFollow.setIncome(income);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date begin_date = sdf.parse(beginDate);
        Date end_date = sdf.parse(endDate);
        managerFollow.setBeginDate(begin_date);
        managerFollow.setEndDate(end_date);
        managerFollow.setContent(content);
        managerFollow.setResolveContent(resolve_content);
        managerFollow.setProjectId(project_id);
        managerFollow.setIsAgree(0);
        managerFollow.setIsEnable(0);
        managerFollow.setCreateTime(new Date());
        if(type.equals("0")){
            //运营跟踪
            managerFollow.setType(0);
        }else if(type.equals("1")){
            //运营解决
            managerFollow.setType(1);
        }
        int result = managerFollowService.insert(managerFollow);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 跟踪完成(项目完成)
     * @param id 项目id
     * @return
     * @throws Exception
     */
    @MobileMethod(methodno = "MProjectFinsih", isLogin = true)
    public MRet.Builder ProjectFinsih(String id)throws Exception{
        if (StringUtils.isBlank(id)) throw new MobException("id");
//        ProjectMessage projectMessage = projectMessageService.selectByPrimaryKey(id);
        
        
        ProjectConnectExample example = new ProjectConnectExample();
        example.createCriteria().andProjectIdEqualTo(id).andZaitiTypeIsNotNull();
        List<ProjectConnect> list = projectConnectService.selectByExample(example);
        
        CompanyRegisterExample example2 = new CompanyRegisterExample();
        example2.createCriteria().andProjectIdEqualTo(id);
        List<CompanyRegister> list2 = companyRegisterService.selectByExample(example2);
        
        if(list.get(0)==null){
            throw new MobException("您访问的内容不存在");
        }
        ProjectConnect projectConnect = list.get(0);
        String zaiti = projectConnect.getZaitiType();
        if(list2.get(0)==null){
            throw new MobException("您访问的内容不存在");
        }
        CompanyRegister companyRegister = list2.get(0);
        companyRegister.setFinalZaiti(zaiti);
        int result2 = companyRegisterService.updateByPrimaryKeySelective(companyRegister);
        if(result2==0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        ProjectMessage projectMessage = new ProjectMessage();
        projectMessage.setId(id);
        //对接完成
        projectMessage.setProjectState(5);
        projectMessage.setIsEnable(0);
        int result = projectMessageService.updateByPrimaryKeySelective(projectMessage);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        
        MRet.Builder ret = MRet.newBuilder();
        ret.setCode(1);
        return ret;
    }
    
    /**
     * 对接终止
     */
    @MobileMethod(methodno = "MProjectConnectStop", isLogin = true)
    public MRet.Builder ProjectConnectStop(MobileInfo mobileInfo, String projectId)throws Exception{
        if (StringUtils.isBlank(projectId)) throw new MobException("projectId");
        ProjectMessage projectMessage = projectMessageService.selectByPrimaryKey(projectId);
        if(projectMessage.getIsEnable() == 1){
            throw new MobException("项目已经终止");
        }       
        projectMessage.setIsEnable(1);
        int result = projectMessageService.updateByPrimaryKey(projectMessage);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        MRet.Builder ret = MRet.newBuilder();
        ret.setCode(1);
        return ret;
    }
    
    @MobileMethod(methodno = "MProjectConnectFinish", isLogin = true)
    public MRet.Builder ProjectConnectFinish(String projectId, String zaitiType)throws Exception{
        if (StringUtils.isBlank(projectId)) throw new MobException("projectId");
        ProjectMessage projectMessage = projectMessageService.selectByPrimaryKey(projectId);
        if(projectMessage.getIsEnable() == 1){
            throw new MobException("项目已经终止");
        }
        projectMessage.setProjectConnectType(zaitiType);
        int result = projectMessageService.updateByPrimaryKey(projectMessage);
        if(result == 0){
            throw new MobException(MZchError.SERVER_BUSY_ERROR);
        }
        MRet.Builder ret = MRet.newBuilder();
        ret.setCode(1);
        return ret;
    }
}
